package com.toocms.jinjuhang.ui.system

import android.os.Bundle
import androidx.databinding.ObservableField
import com.qmuiteam.qmui.arch.QMUIFragmentActivity
import com.toocms.jinjuhang.config.Constants
import com.toocms.jinjuhang.data.ImageData
import com.toocms.jinjuhang.ui.photoview.PhotoViewAty
import com.toocms.tab.base.BaseViewModel
import com.toocms.tab.base.ItemViewModel
import com.toocms.tab.binding.command.BindingAction
import com.toocms.tab.binding.command.BindingCommand

class ImageItemModel(
    viewModel: BaseViewModel<*>,
    val items: (List<ImageData>) = emptyList(),
    val item: (ObservableField<ImageData>) = ObservableField()
) : ItemViewModel<BaseViewModel<*>>(viewModel) {

    val itemClickBindingCommand = BindingCommand<BindingAction>(BindingAction {
        val imagePaths = ArrayList<String>()
        items.forEach {
            imagePaths += it.imagePath ?: return@forEach
        }
        val bundle = Bundle()
        bundle.putStringArrayList(Constants.BundleKey.KEY_IMAGES, imagePaths)
        bundle.putInt(Constants.BundleKey.KEY_POSITION, items.indexOf(item.get()))
        val photoViewAtyBundle = Bundle()
        photoViewAtyBundle.putBundle(QMUIFragmentActivity.QMUI_INTENT_FRAGMENT_ARG, bundle)
        viewModel.startActivity(PhotoViewAty::class.java, photoViewAtyBundle)
    })

}